<!--
* @description:轮胎使用记录
* @fileName: TireServiceRecord
* @author:李周蓬
* @date:2021-1-
* @后台人员:李周蓬
-->
<template>
  <div>
    <div>
      <el-row>
        <el-col :span="3">车牌号：</el-col>
        <el-col :span="5"
          ><el-select v-model="cardnumber" placeholder="请选择">
            <el-option
              v-for="item in bindData"
              :key="item.value"
              :label="item.License"
              :value="item.CarNumber"
            >
            </el-option> </el-select
        ></el-col>
        <el-col :span="3">轮胎品牌：</el-col>
        <el-col :span="5"
          ><el-input v-model="pin" placeholder="请输入内容"></el-input
        ></el-col>

        <el-col :span="3">规格：</el-col>
        <el-col :span="5"
          ><el-input v-model="gui" placeholder="请输入内容"></el-input
        ></el-col>
      </el-row>
      <el-row>
        <el-col :span="3">使用日期：</el-col>
        <el-col :span="5"
          >  <input type="date" v-model="time">
        </el-col>
      </el-row>
    </div>
    <div>
      <el-row>
        <el-col :span="6" class="kk">
          <el-button type="primary" @click="show">查询</el-button>
          <el-button type="primary">重置</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-button type="primary" @click="tianjia">新增</el-button>
          <el-button type="primary" @click="dels">删除</el-button>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="License" label="车牌号"> </el-table-column>
        <el-table-column prop="TyreBrand" label="轮胎品牌"> </el-table-column>
        <el-table-column prop="Specification" label="规格"> </el-table-column>
        <el-table-column prop="Num" label="数量"> </el-table-column>
        <el-table-column prop="UsePerson" label="使用人"> </el-table-column>
        <el-table-column prop="UseTimes" label="使用日期"> </el-table-column>
        <el-table-column prop="Remark" label="备注"> </el-table-column>
        <el-table-column prop="CreateTimes" label="创建时间"> </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <a href="#" @click="update(scope.row)">编辑</a>
            <a href="#" @click="del(scope.row.Id)">删除</a>
            <a href="#" @click="check(scope.row)">查看</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageindex"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalcount"
      >
      </el-pagination>
    </div>
    <!-- 查看轮胎使用信息 -->
    <el-dialog
      title="查看轮胎使用信息"
      :visible.sync="dialogVisible"
      width="40%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>车牌号：</td>
          <td>
            <el-select v-model="checkData.CarNumber" placeholder="请选择">
              <el-option
                v-for="item in bindData"
                :key="item.value"
                :label="item.License"
                :value="item.CarNumber"
              >
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>轮胎品牌：</td>
          <td>
            <el-input
              v-model="checkData.TyreBrand"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>规格：</td>
          <td>
            <el-input
              v-model="checkData.Specification"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>数量：</td>
          <td>
            <el-input
              v-model="checkData.Num"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>使用日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.UseTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td>
            <el-input
              v-model="checkData.Remark"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>创建日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.CreateTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 编辑轮胎使用信息 -->
    <el-dialog
      title="编辑轮胎使用信息"
      :visible.sync="dialogVisibles"
      width="40%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>车牌号：</td>
          <td>
            <el-select v-model="checkData.CarNumber" placeholder="请选择">
              <el-option
                v-for="item in bindData"
                :key="item.value"
                :label="item.License"
                :value="item.CarNumber"
              >
              </el-option>
            </el-select>
          </td>
        </tr>
        <tr>
          <td>轮胎品牌：</td>
          <td>
            <el-input
              v-model="checkData.TyreBrand"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>规格：</td>
          <td>
            <el-input
              v-model="checkData.Specification"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>数量：</td>
          <td>
            <el-input
              v-model="checkData.Num"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>使用日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.UseTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td>
            <el-input
              v-model="checkData.Remark"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>创建日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.CreateTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="xiu">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      pin: "",
      gui:'',
      cardnumber: "",
      time: "",
      pageindex: 1,
      pagesize: 3,
      totalcount: 0,
      ids: [],
      dialogVisible: false,
      dialogVisibles: false,
      checkData: {
        Id: "",
        TyreNumber: "",
        TyreBrand: "",
        CarNumber: "",
        Specification: "",
        Num: "",
        UsePerson: "",
        UseTime: "",
        Remark: "",
        CreateTime: "",
        IsDelete: "",
      },
      bindData: [],
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.show();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pageindex = val;
      this.show();
      console.log(`当前页: ${val}`);
    },
    handleClose(done) {
      this.$confirm("确认关闭？").then(() => {
        done();
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = [];
      for (var i = 0; i < val.length; i++) {
        this.ids.push(val[i].Id);
      }
    },
    show() {
      this.$axios
        .get("https://localhost:44399/api/app/tyre/show-tyre", {
          params: {
            cardnumber: this.cardnumber,
            pin:this.pin,
            gui:this.gui,
            time: this.time,
            pageindex: this.pageindex,
            pagesize: this.pagesize,
          },
        })
        .then((res) => {
          this.tableData = res.data.PageData;
          this.totalcount = res.data.PageTotal;
        });
    },
    //删除
    del(Id) {
      if (confirm("确定删除吗？")) {
        this.$axios
          .delete(
            "https://localhost:44399/api/app/tyre/" + Id + "/del-tyre"
          )
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    //批量删除
    dels() {
      if (confirm("确定删除吗？")) {
        this.$axios
          .delete(
            "https://localhost:44399/api/app/tyre/dels-tyre?ids=" +
              this.ids
          )
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    check(row) {
      this.checkData = null;
      this.dialogVisible = true;
      this.checkData = row;
    },
    update(row) {
      this.checkData = null;
      this.dialogVisibles = true;
      this.checkData = row;
    },
    xiu() {
      this.$axios
        .put(
          "https://localhost:44399/api/app/tyre/update-tyre",
          this.checkData
        )
        .then((res) => {
          if (res.data > 0) {
            this.$message({
              type: "success",
              message: "修改成功!",
            });
            this.dialogVisibles = false;
            this.show();
          } else {
            this.$message({
              type: "error",
              message: "修改失败!",
            });
          }
        });
    },
    tianjia() {
      this.$router.push("/NewTireServiceRecord");
    },
    bind() {
      this.$axios
        .get("https://localhost:44399/api/app/maintain/bind")
        .then((res) => {
          this.bindData = res.data.PageData;
          this.bindData.unshift({ License: "请选择" });
        });
    },
  },
  created() {
    this.show();
    this.bind();
  },
};
</script>

<style scoped>
.kk {
  margin-top: 20px;
  float: right;
}
</style>